//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package 力扣.题库.未分类;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.PriorityQueue;

public class demo_1124 {
    public demo_1124() {
    }

    public static void main(String[] args) {
        List<List<Integer>> nums = new ArrayList(Arrays.asList(new ArrayList(Arrays.asList(4, 10, 15, 24, 26)), new ArrayList(Arrays.asList(0, 9, 12, 20)), new ArrayList(Arrays.asList(5, 18, 22, 30))));
        demo_1124 demo = new demo_1124();
        int[] out = demo.smallestRange(nums);

        for(int i = 0; i < out.length; ++i) {
            System.out.println(out[i]);
        }

    }

    public int[] smallestRange(final List<List<Integer>> nums) {
        int rangeLeft = 0;
        int rangeRight = Integer.MAX_VALUE;
        int minRange = rangeRight - rangeLeft;
        int max = Integer.MIN_VALUE;
        int size = nums.size();
        final int[] next = new int[size];
        PriorityQueue<Integer> priorityQueue = new PriorityQueue(new Comparator<Integer>() {
            public int compare(Integer index1, Integer index2) {
                return (Integer)((List)nums.get(index1)).get(next[index1]) - (Integer)((List)nums.get(index2)).get(next[index2]);
            }
        });

        for(int i = 0; i < size; ++i) {
            priorityQueue.offer(i);
            max = Math.max(max, (Integer)((List)nums.get(i)).get(0));
        }

        while(true) {
            int minIndex = (Integer)priorityQueue.poll();
            int curRange = max - (Integer)((List)nums.get(minIndex)).get(next[minIndex]);
            if (curRange < minRange) {
                minRange = curRange;
                rangeLeft = (Integer)((List)nums.get(minIndex)).get(next[minIndex]);
                rangeRight = max;
            }

            int var10002 = next[minIndex]++;
            if (next[minIndex] == ((List)nums.get(minIndex)).size()) {
                return new int[]{rangeLeft, rangeRight};
            }

            priorityQueue.offer(minIndex);
            max = Math.max(max, (Integer)((List)nums.get(minIndex)).get(next[minIndex]));
        }
    }
}
